<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>
<form onsubmit="return false">
    <textarea name="message" style="width: 300px; height: 300px"></textarea>
    <input type="button" value="send" onclick="sendmessage(this.form.message.value)">
    <textarea id="text" style="width: 300px; height: 300px"></textarea>
    <input type="button" value="clean" onclick="document.getElementById('text').value=''">
</form>
</body>
<script>
    var socket;

    if(window.WebSocket){
        socket = new WebSocket("ws://localhost:8910/chat")
        socket.onmessage = function (ev) {
            var rt = document.getElementById("text")
            rt.value = rt.value + "\n" + ev.data
        }
        socket.onopen = function(ev){
            var rt = document.getElementById("text")
            rt.value = "连上了～"
        }
        socket.onclose = function (ev) {
            var rt = document.getElementById("text")
            rt.value = rt.value + "\n" + "连接关闭了～"
        }
    }

    function sendmessage(message) {
        if(socket.readyState == WebSocket.OPEN){
            socket.send(message)
        }
    }

</script>
</html>